﻿@{
    ViewBag.Title = "过滤IP";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    var objectId = request('objectId');
    var objectType = request('objectType');
    $(function () {
        GetGrid();
    });
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            url: "../../AuthorizeManage/FilterIP/GetListJson",
            postData: { objectId: objectId, visitType: 1 },
            datatype: "json",
            height: $(window).height() - 115,
            autowidth: true,
            colModel: [
                { label: "主键", name: "F_FilterIPId", hidden: true },
                {
                    label: "访问", name: "F_VisitType", width: 80, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        if (cellvalue == 0) {
                            return '<span value=' + cellvalue + ' class=\"label label-danger\">拒绝</span>';
                        } else {
                            return '<span value=' + cellvalue + ' class=\"label label-success\">授权</span>';
                        }
                    }
                },
                { label: "IP地址(子网掩码)", name: "F_IPLimit", width: 200, align: "left", sortable: false }
            ],
            rowNum: "10000",
            rownumbers: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //授权、拒绝 访问事件
        $("#btn_visitType a.btn-default").click(function () {
            $("#btn_visitType a.btn-default").removeClass("active");
            $(this).addClass("active");
            $gridTable.jqGrid('setGridParam', {
                postData: { objectId: objectId, visitType: $(this).attr('data-value') },
            }).trigger('reloadGrid');
        });
    }
    //新增
    function btn_add() {
        var visitType = $("#btn_visitType a.active").attr('data-value');
        dialogOpen({
            id: "Form",
            title: '添加IP地址',
            url: '/AuthorizeManage/FilterIP/Form?objectId=' + objectId + '&objectType=' + objectType + "&visitType=" + visitType,
            width: "400px",
            height: "260px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("F_FilterIPId");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑IP地址',
                url: '/AuthorizeManage/FilterIP/Form?keyValue=' + keyValue,
                width: "400px",
                height: "260px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("F_FilterIPId");
        if (keyValue) {
            $.RemoveForm({
                url: "../../AuthorizeManage/FilterIP/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的库连接！', 0);
        }
    }
</script>
<div class="titlePanel">
    <div class="title-search">
        <table>
            <tr>
                <td>
                    <div id="btn_visitType" class="btn-group">
                        <a class="btn btn-default active" data-value="1"><i class="fa fa-key"></i>&nbsp;授权访问</a>
                        <a class="btn btn-default" data-value="0"><i class="fa fa-lock"></i>&nbsp;拒绝访问</a>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
            <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
            <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
        </div>
    </div>
</div>
<div class="gridPanel">
    <table id="gridTable"></table>
</div>
